package com.itheima.常用API.递归;

public class 递归2 {
    public static void main(String[] args) {
        int[] arr = {5, 1, 2, 3, 4, 11, 10, 9, 8, 7, 6};
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        System.out.println(" - - - - - - - - - - - - - ");
        kuaiPai(arr, 0, arr.length - 1);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }


    public static void kuaiPai(int[] arr, int left, int right) {
        if (left >= right) {
            return;
        }
        int left0 = left;
        int right0 = right;
        int base = arr[left0];
        while (left != right) {
            while (arr[right] > base && left < right) {
                right--;
            }
            while (arr[left] < base && left < right) {
                left++;
            }
            int temp = arr[right];
            arr[right] = arr[left];
            arr[left] = temp;
        }
        kuaiPai(arr, left0, left - 1);
        kuaiPai(arr, left + 1, right0);
    }
}
